﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data.DisplayOptions2
{
    /// <summary>
    /// 对应概念映射数据  
    /// </summary>
    [Serializable]
    public class DOMapData: EventProperty ,IObjectDataHelper ,  ICloneable 
    {

        public DOMapData()
        {

            this._map = new DOMap();
  
        }




        DOMap _map;
        public DOMap Map
        {
            get { return _map; }
            //set { _map = value; }
        }


        public override void SetIsNeedUpdateDataToFalse()
        {
            base.SetIsNeedUpdateDataToFalse();

            this.isNeedUpdateData = false;

            if (this._map !=null )
            {
                this._map.SetIsNeedUpdateDataToFalse();
            }


        }





        #region 可见性的配置
        public override void ProjAddDataVisibleChanged(bool isVisible)
        {
            base.ProjAddDataVisibleChanged(isVisible);

            this._isShowTab = isVisible;
            if (this._map != null)
            {
                this._map.ProjAddDataVisibleChanged(isVisible);
            }
            else
            {
                this._map = new DOMap();
            }


        }


        public override void ProjDeleteDataVisibleChanged(bool isVisible)
        {
            base.ProjDeleteDataVisibleChanged(isVisible);

            this._isShowTab = isVisible;

            if (this._map !=null )
            {
                this._map.ProjDeleteDataVisibleChanged(isVisible );
            }


        }

        #endregion

        #region IObjectDataHelper 成员

        /// <summary>
        /// 更新副本数据到原始数据数据   判断对应的选项改变，并作出对应的更新动作
        /// </summary>
        /// <param name="obj">副本数据</param>
        public void ResetDataAndTriggerEvent(object obj)
        {
            if (obj == null)
            {
                return;
            }

            DOMapData doMapData = (DOMapData)obj;

            if (doMapData .IsDataChanged ()==false )
            {
                return;
            }

            try
            {
                if (this._map !=null )
                {
                     this._map.ResetDataAndTriggerEvent (doMapData._map);
                }
               
            }
            catch
            {

            }  

            //throw new NotImplementedException();
        }

        public bool IsDataChanged( )
        {
            if (this==null )
            {
                return false;
            }
            if (this._isShowTab == false)
            {
                return false;
            }
            if (this.IsNeedUpdateData == true)
            {
                return true;
            }
            else
            {
                if ((this._map != null && this._map.IsDataChanged() == true))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            //return true;
            //throw new NotImplementedException();
        }

        #endregion


        #region ICloneable 成员

        public object Clone()
        {
            DOMapData obj = (DOMapData)this.MemberwiseClone();

            if (this._map != null)
            {
                obj._map = (DOMap)this._map.Clone();
            }
            else
            {
                obj._map = null;
            }



            return obj;

        }

        #endregion


        #region 暂时不使用

        //public void ResetDOMapData(DOMapData doMapData)
        //{
        //    try
        //    {
        //        this._map.ResetDOMap(doMapData._map);
        //    }
        //    catch
        //    {
        //    }
        //}

        #endregion

    }

}
